//
//  NowayExitVIew.m
//  location
//
//  Created by Dongxiang Xu on 2025/11/10.
//

#import "NowayExitVIew.h"
#import "WXApi.h"

@implementation NowayExitVIew

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView
{
    UIView *infoView = [[UIView alloc] initWithFrame:CGRectMake(12, SCREEN_HEIGHT, SCREEN_WIDTH-24, 210)];
    infoView.layer.masksToBounds = YES;
    [infoView.layer setCornerRadius:40];
    infoView.backgroundColor = RealWhiteColor;
    [self addSubview:infoView];
    
    UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(infoView.width-46, 16, 30, 30)];
    [close setImage:[UIImage imageNamed:@"map_close"] forState:UIControlStateNormal];
    [infoView addSubview:close];
    [[close rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [UIView animateWithDuration:0.3 animations:^{
            infoView.y = SCREEN_HEIGHT;
            self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0];
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, infoView.width, 28)];
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"无法退出，会员未到期";
    title.textColor = BlackColor;
    title.font = MEDIUM_FONT(20);
    [infoView addSubview:title];
    
    UILabel *subTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, title.maxY+6, infoView.width, 24)];
    subTitle.textColor = GraryLightColor;
    subTitle.font = DEFAULT_FONT(14);
    subTitle.textAlignment = NSTextAlignmentCenter;
    subTitle.text = @"如需帮助，请联系客服";
    [infoView addSubview:subTitle];
    
    NSArray *array = @[@"联系客服",@"好的"];
    for (int i = 0; i < array.count; i ++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(32+i*((infoView.width-80)/2+16), subTitle.maxY+28, (infoView.width-80)/2, 52)];
        button.layer.masksToBounds = YES;
        [button.layer setCornerRadius:26];
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button.titleLabel setFont:MEDIUM_FONT(17)];
        if (i==0) {
            [button.layer setBorderWidth:1];
            [button.layer setBorderColor:NormalMainColor.CGColor];
            button.backgroundColor = RealWhiteColor;
            [button setTitleColor:NormalMainColor forState:UIControlStateNormal];
        }else{
            button.backgroundColor = LightBGColor;
            [button setTitleColor:RealBlackColor forState:UIControlStateNormal];
        }
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (i==0) {
                WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init];
                req.corpid = @"wwd398f4f09a46d09b";    //企业ID
                req.url = @"https://work.weixin.qq.com/kfid/kfcf5c99c0434b5983c";            //客服URL
                [WXApi sendReq:req completion:^(BOOL success) {
                    
                }];
            }else if (i==1){
                [UIView animateWithDuration:0.3 animations:^{
                    infoView.y = SCREEN_HEIGHT;
                    self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0];
                } completion:^(BOOL finished) {
                    [self removeFromSuperview];
                }];
            }
        }];
        [infoView addSubview:button];
    }
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self insertSubview:bgView atIndex:0];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [[tap rac_gestureSignal] subscribeNext:^(id x) {
        [UIView animateWithDuration:0.3 animations:^{
            infoView.y = SCREEN_HEIGHT;
            self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0];
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }];
    [bgView addGestureRecognizer:tap];
    
    [UIView animateWithDuration:0.3 animations:^{
        infoView.y = SCREEN_HEIGHT-244;
        self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0.4];
    }];
}


@end
